package com.authapi.sample.api.model.Response.Common;

import lombok.Data;

import java.util.List;
@Data
public class ResultList<T> {
    private int code;
    private String message;
    private List<T> data;
    private int total;

    public ResultList (int code, String message, List<T> data, int total) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    public static<T>  ResultList<List<T>> Success(List<T> data, int count) {
        return new ResultList(200,"Success",data,count);
    }

    public static<T>  ResultList<List<T>> Success(List<T> data){
        int _total = 0;
        if(data!=null){
            _total = data.size();
        }
        return new ResultList(200,"Success",data,_total);
    }


    public static<T>  ResultList<List<T>> Fail(String message){
        return new ResultList<List<T>>(401,message,null,0);

    }
}
